Skip to content

Recognise empty scale with limits = <function> as empty #5948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5945.

Briefly, a discrete position scale was treated as empty when range data is absent and limits are NULL.
This PR also treats such scale as empty when range data is absent and limits is a function.
In such cases, functions don't recieve proper 'natural data limits' because the range data is absent.
Potentially, this would cause troubles downstream, so I thought it best to treat such cases as empty scales.

Reprex from issue, note the empty plot instead of errors:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

df <- data.frame(
  level = factor(character(), "1"),
  x = numeric(),
  meanX = numeric()
)

ggplot(df) + 
  geom_col(aes(x = meanX, y = level, fill = level)) +
  labs(x = NULL, y = NULL, fill = NULL, title = "title") +
  scale_y_discrete(labels = NULL, limits = rev, drop = FALSE)

Created on 2024-06-19 with reprex v2.1.0

@teunbrand teunbrand marked this pull request as ready for review June 19, 2024 07:29
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit 98f5e12 into tidyverse:main Jul 12, 2024
11 checks passed
@teunbrand teunbrand deleted the discrete_empty branch July 12, 2024 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scale_y_discrete() fails without data to plot
2 participants